/**
 * Captain
 * © 2017 Captain copyright，All rights reserved.
 * http://www.sccaptain.com.cn
 * 
 * JAVA : 8
 * 文  件  名: RegistrationApplicationUser.java
 * 创  建  人: Roc Zheng (roc.djz@gmail.com)
 * 创建时间: 2017年10月16日 上午11:38:51
 * 版         本: 1.0.0
 * 备         注:
 * 修订历史:
 */
package com.material.c2c.web.sys.security;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;

import com.cpt.security.identity.account.model.AccountUserDetails;
import com.cpt.security.identity.account.model.GrantedPermission;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.material.c2c.core.User;

/**
 * 
 * 
 * @since 1.0
 * @version 1.0
 * @author Roc Zheng (roc.djz@gmail.com)
 */
@JsonIgnoreProperties({"password", "accountNonExpired", "accountNonLocked", "credentialsNonExpired", "enabled", "roles"})
public class RegistrationApplicationUser extends AccountUserDetails implements User {
  private static final long serialVersionUID = 1L;

  /**
   * 获取 zoneCode。
   * @return zoneCode。
   */
  public String getZoneCode() {
    return null;
  }

  /**
   * 获取别名。
   * @return 别名字符串。
   */
  public String getNickname() {
    return getRealName();
  }

  @Override
  @JsonIgnore
  public List<String> getRoles() {
    return getAuthorities().stream()
      .map(authorities -> authorities.getAuthority())
      .collect(Collectors.toList());
  }

  public RegistrationApplicationUser(String username, String password) {
    this(username, password, username, null, null, null, true, true, true, true, AuthorityUtils.NO_AUTHORITIES, Collections.emptyList());
  }

  public RegistrationApplicationUser(String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
    this(username, password, null, null, null, null, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities, Collections.emptyList());
  }

  public RegistrationApplicationUser(String username, String password, String id, String email, String realName, String phoneNumber, Collection<? extends GrantedAuthority> authorities, Collection<? extends GrantedPermission> permissions) {
    super(username, password, id, email, realName, phoneNumber, authorities, permissions);
  }

  public RegistrationApplicationUser(String username, String password, String id, String email, String realName, String phoneNumber, boolean enabled,
      boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities, Collection<? extends GrantedPermission> permissions) {
    super(username, password, id, email, realName, phoneNumber, enabled, accountNonLocked, authorities, permissions);
  }

  public RegistrationApplicationUser(String username, String password, String id, String email, String realName, String phoneNumber, boolean enabled,
      boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities, Collection<? extends GrantedPermission> permissions) {
    super(username, password, id, email, realName, phoneNumber, enabled, accountNonExpired, credentialsNonExpired, accountNonExpired, authorities, permissions);
  }
}
